<?php
class statsComponents extends sfComponents {

	public function executeDefault()
	{
		$username = $this->twitter_name;
		$this->tweets = $username ? Utilities::getTwitterStreams($username) : null;
	}


	public function executeMonthly_sales_chart()
	{

		$q = Doctrine_Query::create()
		->select('d.created_at')
		->addSelect('date_format(d.created_at, "%d %M") as sales_date')
		->addSelect('SUM(o.amount) as sales_amount')
		->from('DistributedVideos d')
		->innerJoin('d.Video v')
		->innerJoin('d.Transaction t')
		->innerJoin('t.OrderDetail o')
		->where('v.item_id = '.$this->item->getId().' and d.created_at BETWEEN (SYSDATE() - INTERVAL 30 DAY) AND SYSDATE()')
		->groupBy('day(d.created_at)')
		->orderBy('d.created_at asc');

		$q->execute();
		$this->results = $q->execute();
	}

	public function executeMonthly_count_chart()
	{

		$q = Doctrine_Query::create()
		->select('d.created_at')
		->addSelect('date_format(d.created_at, "%d %M") as sales_date')
		->addSelect('COUNT(t.id) as sales_amount')
		->from('DistributedVideos d')
		->innerJoin('d.Video v')
		->innerJoin('d.Transaction t')
		->innerJoin('t.OrderDetail o')
		->where('v.item_id = '.$this->item->getId().' and d.created_at BETWEEN (SYSDATE() - INTERVAL 30 DAY) AND SYSDATE()')
		->groupBy('day(d.created_at)')
		->orderBy('d.created_at asc');

		$q->execute();
		$this->results = $q->execute();
	}




}
?>